package cm.cool.web.service.businesscard;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import cm.cool.web.bean.BusinessCard;
import cm.cool.web.data.BusinessCardMapper;
import cm.cool.web.util.respon.PaginationDto;
import cm.cool.web.util.respon.R;
import cm.cool.web.util.respon.ResultEncoding;

@Service
public class BusinessCardService {

	@Autowired
	BusinessCardMapper businessCardMapper;

	/**
	 * 条件查找所有名片信息
	 * @param record
	 * @return
	 */
	public R selectByPrimaryAll(BusinessCard record,PaginationDto paginationDto){
		
		R r=new R();
		try {
			PageHelper.startPage(paginationDto.getCurrentPageNum(), paginationDto.getPerPageSize());
			paginationDto.setEntitys(businessCardMapper.selectByPrimaryAll(record));
			int count = businessCardMapper.selectByPrimaryAllCount(record);
			paginationDto.setTotalCount(count);
			paginationDto.setTotalPageNum((int)Math.ceil((count*1.0) / paginationDto.getPerPageSize()));
			r.setData(paginationDto);
		} catch (Exception e) {
			e.printStackTrace();
			r.setCode(ResultEncoding.R_ERR);
			r.setMsg("查询异常");
			return r;
		}
		return r;
	}
}
